package com.example.app3_1;

// 导入必要的包
import android.content.Intent;
import android.graphics.Color;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;

public class ProfileEditActivity extends AppCompatActivity {
    private String username;
    private TextView tvInterest;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_profile_edit);

        // 接收用户名
        Intent intent = getIntent();
        if (intent != null) {
            username = intent.getStringExtra("username");
        }

        // 显示用户名
        TextView tvUsername = findViewById(R.id.tv_username);
        tvUsername.setText("用户名: " + username);

        // 返回按钮
        Button btnBack = findViewById(R.id.btn_back);
        btnBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 点击反馈
                v.setBackgroundColor(Color.parseColor("#CCCCCC"));
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        v.setBackgroundColor(Color.TRANSPARENT);
                    }
                }, 100);

                // 返回上一页
                finish();
            }
        });

        // 兴趣文本框
        tvInterest = findViewById(R.id.tv_interest);
        tvInterest.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 跳转到兴趣选择页面
                Intent interestIntent = new Intent(ProfileEditActivity.this, InterestSelectionActivity.class);
                startActivityForResult(interestIntent, 1);
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == 1 && resultCode == RESULT_OK && data != null) {
            // 获取选择的兴趣
            String interest = data.getStringExtra("interest");
            tvInterest.setText("兴趣: " + interest);
        }
    }
}
